package org.jeecg.basic.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.jeecg.basic.entity.MesPartGroup;
import org.jeecg.basic.service.IMesPartGroupService;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * (MesPartGroup)表控制层
 *
 * @author liting
 * @since 2024-09-01 11:44:09
 */
@RestController
@RequestMapping("/basic/mesPartGroup")
public class MesPartGroupController extends JeecgController<MesPartGroup, IMesPartGroupService> {
    /**
     * 服务对象
     */
    @Resource
    private IMesPartGroupService mesPartGroupService;

    /**
     * 分页列表查询666
     *
     * @param partGroup
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "产品组配置-分页列表查询")
    @ApiOperation(value="产品组配置-分页列表查询", notes="产品组配置-分页列表查询")
    @GetMapping(value = "/list")
    @DS("#header.his")
    public Result<IPage<MesPartGroup>> queryPageList(MesPartGroup partGroup,
                                                      @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                      @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                      HttpServletRequest req) {
        QueryWrapper<MesPartGroup> queryWrapper = QueryGenerator.initQueryWrapper(partGroup, req.getParameterMap());
        queryWrapper.orderByAsc("id");
        Page<MesPartGroup> page = new Page<MesPartGroup>(pageNo, pageSize);
        IPage<MesPartGroup> pageList = mesPartGroupService.page(page, queryWrapper);

        return Result.OK(pageList);
    }

    @ApiOperation(value="产品组配置-列表查询", notes="产品组配置-列表查询")
    @GetMapping(value = "/groupList")
    @DS("#header.his")
    public Result<List<MesPartGroup>> queryGroupList(MesPartGroup partGroup,
                                                        HttpServletRequest req) {
        QueryWrapper<MesPartGroup> queryWrapper = QueryGenerator.initQueryWrapper(partGroup, req.getParameterMap());
        List<MesPartGroup> dataList = mesPartGroupService.list(queryWrapper);
        return Result.OK(dataList);
    }


    /**
     *   添加
     *
     * @param partGroup
     * @return
     */
    @AutoLog(value = "产品组配置-添加")
    @ApiOperation(value="产品组配置-添加", notes="产品组配置-添加")
    //@RequiresPermissions("org.jeecg.modules.demo:mes_routing_cfg:add")
    @PostMapping(value = "/add")
    @DS("#header.line")
    public Result<String> add(@RequestBody MesPartGroup partGroup) {
        mesPartGroupService.save(partGroup);
        return Result.OK("添加成功！");
    }

    /**
     *  编辑
     *
     * @param partGroup
     * @return
     */
    @AutoLog(value = "产品组配置-编辑")
    @ApiOperation(value="产品组配置-编辑", notes="产品组配置-编辑")
    //@RequiresPermissions("org.jeecg.modules.demo:mes_routing_cfg:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
    @DS("#header.line")
    public Result<String> edit(@RequestBody MesPartGroup partGroup) {
        mesPartGroupService.updateById(partGroup);

        return Result.OK("编辑成功!");
    }

    /**
     *   通过选中对象删除
     *
     * @param partGroup
     * @return
     */
    @AutoLog(value = "产品组配置-通过id删除")
    @ApiOperation(value="产品组配置-通过id删除", notes="产品组配置-通过id删除")
    //@RequiresPermissions("org.jeecg.modules.demo:mes_routing_cfg:delete")
    @RequestMapping(value = "/delete")
    public Result<String> delete(@RequestBody MesPartGroup partGroup) {
        mesPartGroupService.removeById(partGroup);
        return Result.OK("删除成功!");
    }

    /**
     *  批量删除
     *
     * @param list
     * @return
     */
    @AutoLog(value = "产品组配置-批量删除")
    @ApiOperation(value="产品组配置-批量删除", notes="产品组配置-批量删除")
    //@RequiresPermissions("org.jeecg.modules.demo:mes_routing_cfg:deleteBatch")
    @RequestMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestBody List<MesPartGroup> list) {
        list.forEach(item->{
            mesPartGroupService.removeById(item);
        });
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "产线路由配置-通过id查询")
    @ApiOperation(value="产品组配置-通过id查询", notes="产品组配置-通过id查询")
    @GetMapping(value = "/queryById")
    @DS("#header.his")
    public Result<MesPartGroup> queryById(@RequestParam(name="id",required=true) String id) {
        MesPartGroup partGroup = mesPartGroupService.getById(id);
        if(partGroup==null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(partGroup);
    }

    /**
     * 导出excel
     *
     * @param request
     * @param partGroup
     */
    //@RequiresPermissions("org.jeecg.modules.demo:mes_routing_cfg:exportXls")
    @RequestMapping(value = "/exportXls")
    @DS("#header.his")
    public ModelAndView exportXls(HttpServletRequest request, MesPartGroup partGroup) {
        return super.exportXls(request, partGroup, MesPartGroup.class, "产品组配置");
    }

    /**
     * 通过excel导入数据
     *
     * @param request
     * @param response
     * @return
     */
    //@RequiresPermissions("mes_routing_cfg:importExcel")
    @DS("#header.line")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, MesPartGroup.class);
    }
}

